package com.fdb.efp.nls.api.rest;

import com.fdb.basic.framework.core.constant.ApplicationConstance;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.util.TimeUtil;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.basic.sequence.service.facade.SequenceService;
import com.fdb.efp.nls.service.facade.UploadFilesListService;
import com.fdb.efp.nls.service.vo.UploadFilesListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.UUID;

/**
 * 需求编号：【2019D0509】（业务提的需求编号）
 * 问题编号：【】（若不是因为修复问题而新增该类，则留空）
 * 开发人员：【wanglh4】
 * 创建日期：【2019/12/30 11:19】
 * 功能描述：
 */
@RestController
@RequestMapping("/api")
public class UploadFilesListController  extends AbstractController {
    @Autowired
    @Qualifier("uploadFilesListService")
    private UploadFilesListService uploadFilesListService;
    @Autowired
    @Qualifier("dbSeqService")
    private SequenceService sequenceService;

    @RequestMapping(value="/s/mon/reliefAnn/msg", method= RequestMethod.POST)
    public @ResponseBody
    ResponseData<Integer> insertFiles(@RequestBody UploadFilesListVO uploadFilesListVO) {
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        uploadFilesListVO.setFileSignCode(fileSignCode);
        uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
        uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        int outputVo = uploadFilesListService.insert(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    @RequestMapping(value="/s/mon/reliefAnn/msg", method=RequestMethod.PUT)
    public @ResponseBody
    ResponseData<Integer> updateByPk(@RequestBody UploadFilesListVO uploadFilesListVO) {
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        int outputVo = uploadFilesListService.updateByPk(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    @RequestMapping(value="/s/delMon/reliefAnn/msg", method=RequestMethod.DELETE)
    public @ResponseBody
    ResponseData<Integer> deleteByPk(@RequestBody UploadFilesListVO uploadFilesListVO) {
        int outputVo = uploadFilesListService.deleteByPk(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    @RequestMapping(value="/mon/relief/ann", method=RequestMethod.POST)
    public @ResponseBody
    ResponseData<List<UploadFilesListVO>> queryByConditions(@RequestBody UploadFilesListVO uploadFilesListVO) {
        List<UploadFilesListVO> outputVo = uploadFilesListService.queryByConditions(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    /**
     * 核销附件上传
     * @author xiezw
     * @params  * @param vo
     * @date 2020/3/19 15:12
     * @version 0.1
     */
    @RequestMapping(value="/s/mon/reliefAnn/msg/cwoa", method= RequestMethod.POST)
    public @ResponseBody
    ResponseData<String> insertFilesCwoa(@RequestBody UploadFilesListVO uploadFilesListVO) {
        int outputVo = 0;
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        String tSeq = "";
        try {
            tSeq = sequenceService.getSequence("WO_SEQ_ID","null","null");
            uploadFilesListVO.setFlowAppNo(tSeq);
            uploadFilesListVO.setBizSerno(tSeq);
            uploadFilesListVO.setFileSignCode(fileSignCode);
            uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
            uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
            uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
            outputVo = uploadFilesListService.insert(uploadFilesListVO);
        } catch (Exception e) {
            logger.error("********************************************插入数据出错，异常信息为：", e.getMessage());
            outputVo = -1;
            return setResponseMessage(tSeq,"插入数据失败", ApplicationConstance.FAILURE,false);
        }
        return setResponseMessage(tSeq,"插入数据成功", ApplicationConstance.SUCCESS,true);
    }

    @RequestMapping(value="/s/mon/reliefAnn/msg/cwoa", method=RequestMethod.PUT)
    public @ResponseBody
    ResponseData<Integer> updateByPkCwoa(@RequestBody UploadFilesListVO uploadFilesListVO) {
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        uploadFilesListVO.setFileSignCode(fileSignCode);
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
        uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
        int outputVo = uploadFilesListService.insert(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    /**
     * 额度解冻附件上传
     * @author xiezw
     * @params  * @param vo
     * @date 2020/3/19 15:12
     * @version 0.1
     */
    @RequestMapping(value="/s/limit/unfrz/uploadFile/his", method= RequestMethod.POST)
    public @ResponseBody
    ResponseData<String> insertFilesLmtUnfrz(@RequestBody UploadFilesListVO uploadFilesListVO) {
        int outputVo = 0;
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        String tSeq = "";
        try {
            tSeq = sequenceService.getSequence("UNFRZ_SERNO","null","null");
            uploadFilesListVO.setFlowAppNo(tSeq);
            uploadFilesListVO.setBizSerno(tSeq);
            uploadFilesListVO.setFileSignCode(fileSignCode);
            uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
            uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
            uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
            outputVo = uploadFilesListService.insert(uploadFilesListVO);
        } catch (Exception e) {
            logger.error("********************************************插入数据出错，异常信息为：", e.getMessage());
            outputVo = -1;
            return setResponseMessage(tSeq,"插入数据失败", ApplicationConstance.FAILURE,false);
        }
        return setResponseMessage(tSeq,"插入数据成功", ApplicationConstance.SUCCESS,true);
    }

    @RequestMapping(value="/s/limit/unfrz/uploadFile/his", method=RequestMethod.PUT)
    public @ResponseBody
    ResponseData<Integer> updateByPkLmtUnfrz(@RequestBody UploadFilesListVO uploadFilesListVO) {
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        uploadFilesListVO.setFileSignCode(fileSignCode);
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
        uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
        int outputVo = uploadFilesListService.insert(uploadFilesListVO);
        return getResponseData(outputVo);
    }

    private ResponseData<String> setResponseMessage(String outputVo , String message, String code, boolean isSuccess) {
        ResponseData<String> responseData = new ResponseData<String>();
        responseData.setRows(outputVo);
        responseData.setMessage(message);
        responseData.setCode(code);
        responseData.setSuccess(isSuccess);
        return responseData;
    }

    /**
     * 风险代理上传记录
     * @author xiezw
     * @params  * @param vo
     * @date 2020/7/1 9:33
     * @version 0.1
     */
    @RequestMapping(value="/collt/task/distrs/uploadFile/his", method= RequestMethod.POST)
    public @ResponseBody
    ResponseData<String> insertFilesDistrs(@RequestBody UploadFilesListVO uploadFilesListVO) {
        int outputVo = 0;
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        uploadFilesListVO.setFileSignCode(fileSignCode);
        uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
        uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        outputVo = uploadFilesListService.insert(uploadFilesListVO);
        return setResponseMessage(uploadFilesListVO.getFlowAppNo(),"插入数据成功", ApplicationConstance.SUCCESS,true);
    }

    /**
     * 检查登记附件上传
     * @author xiezw
     * @params  * @param vo
     * @date 2020/3/19 15:12
     * @version 0.1
     */
    @RequestMapping(value="/upload/file/list/psp", method= RequestMethod.POST)
    public @ResponseBody
    ResponseData<String> insertPsp(@RequestBody UploadFilesListVO uploadFilesListVO) {
        int outputVo = 0;
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        String tSeq = "";
        try {
            tSeq = sequenceService.getSequence("PSP_CHKCUS_BIZ_SERNO","null","null");
            uploadFilesListVO.setFlowAppNo(tSeq);
            uploadFilesListVO.setBizSerno(tSeq);
            uploadFilesListVO.setFileSignCode(fileSignCode);
            uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
            uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
            uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
            outputVo = uploadFilesListService.insert(uploadFilesListVO);
        } catch (Exception e) {
            logger.error("********************************************插入数据出错，异常信息为：", e.getMessage());
            outputVo = -1;
            return setResponseMessage(tSeq,"插入数据失败", ApplicationConstance.FAILURE,false);
        }
        return setResponseMessage(tSeq,"插入数据成功", ApplicationConstance.SUCCESS,true);
    }

    @RequestMapping(value="/upload/file/list/psp", method=RequestMethod.PUT)
    public @ResponseBody
    ResponseData<Integer> updatePsp(@RequestBody UploadFilesListVO uploadFilesListVO) {
        String fileSignCode = UUID.randomUUID().toString().replace("-","");
        uploadFilesListVO.setFileSignCode(fileSignCode);
        uploadFilesListVO.setLastUploadTime(TimeUtil.getCurrentDateTime());
        uploadFilesListVO.setLastUploadUser(uploadFilesListVO.getUploadUser());
        uploadFilesListVO.setUploadTime(TimeUtil.getCurrentDateTime());
        int outputVo = uploadFilesListService.insert(uploadFilesListVO);
        return getResponseData(outputVo);
    }
}
